var zTreeObjCplb,zTreeObjZrjb,zTreeObjZrbhfs,zTreeObjNd,zTreeObjZd;
var treeNodesCplb,treeNodesZrjb,treeNodesZrbhfs,treeNodesNd,treeNodesZd;
var cplbSelectedId="",zrjbSelectedId="",zrbhfsSelectedId="",ndSelectedId="",zdSelectedId="";
var cplbSelectedName="",zrjbSelectedName="",zrbhfsSelectedName="",ndSelectedName="",zdSelectedName="";
var settingCplb = { //藏品类别
    data: {  
        simpleData: {  
            enable: true,  
            idKey: "id",  
            pIdKey: "parentid",  
            rootPId: 0  
        }
    },
    callback: {
    	onClick: zTree1OnClick
	}
};

 var settingZrjb = {//自然级别
    data: {  
        simpleData: {  
            enable: true,  
            idKey: "id",  
            pIdKey: "parentid",  
            rootPId: 0  
        }  
    },
    callback: {
    	onClick: zTree2OnClick
	}
};
var settingZrbhfs = {//自然保护方式
    data: {  
        simpleData: {  
            enable: true,  
            idKey: "id",  
            pIdKey: "parentid",  
            rootPId: 0  
        }  
    },
    callback: {
    	onClick: zTree3OnClick
	}
};

var settingNd = {//年代
    data: {  
        simpleData: {  
            enable: true,  
            idKey: "id",  
            pIdKey: "parentid",  
            rootPId: 0  
        }  
    },
    callback: {
    	onClick: zTree4OnClick
	}
};

var settingZd = {//质地
    data: {  
        simpleData: {  
            enable: true,  
            idKey: "id",  
            pIdKey: "parentid",  
            rootPId: 0  
        }  
    },
    callback: {
    	onClick: zTree5OnClick
	}
}; 

//藏品类别节点点击事件
function zTree1OnClick(event, treeId, treeNode){
	//生成对应的列表
	cplbSelectedId = treeNode.id;
	cplbSelectedName = treeNode.name;
	$('#cplbparentNode').val(treeNode.id);				
	$('#cplbparentNodeName').val(treeNode.name);
	var params = {'tableName':'jb_cplb','id':cplbSelectedId};
	$('#jb_cplb').bootstrapTable('refresh',{query:params});
}

function zTree2OnClick(event, treeId, treeNode){
	zrjbSelectedId = treeNode.id;
	zrjbSelectedName = treeNode.name;
	$('#zrjbparentNode').val(treeNode.id);				
	$('#zrjbparentNodeName').val(treeNode.name);
	var params = {'tableName':'jb_zrjb','id':zrjbSelectedId};
	$('#jb_zrjb').bootstrapTable('refresh',{query:params});
}

function zTree3OnClick(event, treeId, treeNode){
	zrbhfsSelectedId = treeNode.id;
	zrbhfsSelectedName = treeNode.name;
	$('#zrbhfsparentNode').val(treeNode.id);
	$('#zrbhfsparentNodeName').val(treeNode.name);
	var params = {'tableName':'jb_zrbhfs','id':zrbhfsSelectedId};
	$('#jb_zrbhfs').bootstrapTable('refresh',{query:params});
}

function zTree4OnClick(event, treeId, treeNode){
	ndSelectedId = treeNode.id;
	ndSelectedName = treeNode.name;
	$('#ndparentNode').val(treeNode.id);
	$('#ndparentNodeName').val(treeNode.name);
	var params = {'tableName':'jb_nd','id':ndSelectedId};
	$('#jb_nd').bootstrapTable('refresh',{query:params});
}

function zTree5OnClick(event, treeId, treeNode){
	zdSelectedId = treeNode.id;
	zdSelectedName = treeNode.name;
	$('#zdparentNode').val(treeNode.id);
	$('#zdparentNodeName').val(treeNode.name);
	var params = {'tableName':'jb_zd','id':zdSelectedId};
	$('#jb_zd').bootstrapTable('refresh',{query:params});
}

//记录当前操作的基表
var currentJb="jb_cplb";
$(document).ready(function () {
	$("#functionNav").attr("href",navAddr);
	//默认加载第一课树
	treeNodesCplb = ajaxResult("post",false,ProjectName+"/sysmanage.getTreeNodes.do",{'tableName':'jb_cplb'});
	zTreeObjCplb = $.fn.zTree.init($("#ztreeCplb"), settingCplb, treeNodesCplb.rows);
	//设置默认选择第一个节点
	cplbSelectedId = treeNodesCplb.rows[0].id;
	cplbSelectedName = treeNodesCplb.rows[0].name;
	var cplbNodeObject = zTreeObjCplb.getNodeByParam("id",cplbSelectedId,null);
	zTreeObjCplb.selectNode(cplbNodeObject);
	//填充增加修改模态框中的隐藏字段	
	$('#cplbparentNode').val(cplbSelectedId);				
	$('#cplbparentNodeName').val(cplbSelectedName);	
	createTableWithOutPage('#jb_cplb',ProjectName+'/sysmanage.getTableByTree.do','id',treeColumns,{'tableName':'jb_cplb','id':1});	
	//点击左侧导航栏的响应
	$(".col-sm-2 li").click(function(){
		//获取基表维护表名
		var tblname = $(this).children("a").attr("href").replace('#tab_','');
		currentJb ="jb_"+tblname;
		//显示对应的tab-pane
		$(".tab-pane").hide();
		$("#tab_"+tblname).show();
		if((tblname=='cplb')||(tblname=='zrjb')||(tblname=='zrbhfs')||(tblname=='nd')||(tblname=='zd')){//生成树	
			switch(tblname){
			case 'cplb':
				treeNodesCplb = ajaxResult("post",false,ProjectName+"/sysmanage.getTreeNodes.do",{'tableName':'jb_cplb'});
				zTreeObjCplb = $.fn.zTree.init($("#ztreeCplb"), settingCplb, treeNodesCplb.rows);
				//设置默认选择第一个节点
				cplbSelectedId = treeNodesCplb.rows[0].id;
				cplbSelectedName = treeNodesCplb.rows[0].name;
				var cplbNodeObject = zTreeObjCplb.getNodeByParam("id",cplbSelectedId,null);
				zTreeObjCplb.selectNode(cplbNodeObject);
				break;
			case 'zrjb':
				treeNodesZrjb = ajaxResult("post",false,ProjectName+"/sysmanage.getTreeNodes.do",{'tableName':'jb_zrjb'});
				zTreeObjZrjb = $.fn.zTree.init($("#ztreeZrjb"), settingZrjb, treeNodesZrjb.rows);
				//设置默认选择第一个节点
				zrjbSelectedId = treeNodesZrjb.rows[0].id;
				zrjbSelectedName = treeNodesZrjb.rows[0].name;
				var zrjbNodeObject = zTreeObjZrjb.getNodeByParam("id",zrjbSelectedId,null);	
				zTreeObjZrjb.selectNode(zrjbNodeObject);
				createTableWithOutPage('#jb_zrjb',ProjectName+'/sysmanage.getTableByTree.do','id',treeColumns,{'tableName':'jb_zrjb','id':1});				
				break;
			case 'zrbhfs':	
				treeNodesZrbhfs = ajaxResult("post",false,ProjectName+"/sysmanage.getTreeNodes.do",{'tableName':'jb_zrbhfs'});
				zTreeObjZrbhfs = $.fn.zTree.init($("#ztreeZrbhfs"), settingZrbhfs, treeNodesZrbhfs.rows);
				//设置默认选择第一个节点
				zrbhfsSelectedId = treeNodesZrbhfs.rows[0].id;
				zrbhfsSelectedName = treeNodesZrbhfs.rows[0].name;
				var zrbhfsNodeObject = zTreeObjZrbhfs.getNodeByParam("id",zrbhfsSelectedId,null);
				zTreeObjZrbhfs.selectNode(zrbhfsNodeObject);
				createTableWithOutPage('#jb_zrbhfs',ProjectName+'/sysmanage.getTableByTree.do','id',treeColumns,{'tableName':'jb_zrbhfs','id':1});
				break;
			case 'nd':
				treeNodesNd = ajaxResult("post",false,ProjectName+"/sysmanage.getTreeNodes.do",{'tableName':'jb_nd'});
				zTreeObjNd = $.fn.zTree.init($("#ztreeNd"), settingNd, treeNodesNd.rows);
				//设置默认选择第一个节点
				ndSelectedId = treeNodesNd.rows[0].id;
				ndSelectedName = treeNodesNd.rows[0].name;
				var ndNodeObject = zTreeObjNd.getNodeByParam("id",ndSelectedId,null);
				zTreeObjNd.selectNode(ndNodeObject);
				createTableWithOutPage('#jb_nd',ProjectName+'/sysmanage.getTableByTree.do','id',treeColumns,{'tableName':'jb_nd','id':1});
				break;
			case 'zd':
				treeNodesZd = ajaxResult("post",false,ProjectName+"/sysmanage.getTreeNodes.do",{'tableName':'jb_zd'});
				zTreeObjZd = $.fn.zTree.init($("#ztreeZd"), settingZd, treeNodesZd.rows);
				//设置默认选择第一个节点
				zdSelectedId = treeNodesZd.rows[0].id;
				zdSelectedName = treeNodesZd.rows[0].name;
				var zdNodeObject = zTreeObjZd.getNodeByParam("id",zdSelectedId,null);
			    zTreeObjZd.selectNode(zdNodeObject);
				createTableWithOutPage('#jb_zd',ProjectName+'/sysmanage.getTableByTree.do','id',treeColumns,{'tableName':'jb_zd','id':1});
				break;
			}	
			$('#'+tblname+'parentNode').val(eval(tblname+'SelectedId'));				
		    $('#'+tblname+'parentNodeName').val(eval(tblname+'SelectedName'));		    
		}else{//生成table
			if(currentJb!="jb_bmgz"){
				var param = {'tableName':currentJb};
				createTable('#'+currentJb,ProjectName+'/sysmanage.getTable.do','id',eval(tblname+'Columns'),param);
			}else{
				createTableWithOutPage('#jb_bmgz',ProjectName+'/sysmanage.getFggzListByBmid.do','id',eval(tblname+'Columns'));
			}
			
		}
	});		
	
	//获取并填充部门列表
  	var bmJson = ajaxResult("get",false,ProjectName+"/root.getOrganization.do",{});
  	if(bmJson.status="ok"){
		var result="<option value=''>请选择</option>";
		if(bmJson.rows!=null || bmJson.rows!=""){
			$.each(bmJson.rows,function(index,content){
				if(content['name'].indexOf("博物馆") <0 && content['name'] !="馆领导")
					result +="<option value="+content['orgid']+">"+content['name']+"</option>";
			})
		}
		$("select[name=bmid]").html(result);
	}else{
		alertFunc("获取部门列表失败！");
		return false;
	}	
	
	//获取并填充分管馆长列表
  	var fggzJson = ajaxResult("get",false,ProjectName+"/root.getUserListByOrg.do",{'orgId':'guanlingdao'});
  	if(fggzJson.status="ok"){
  		loadSelect("select[name=fggzid]",fggzJson.rows,'userid','username');
	}else{
		alertFunc("获取分管馆长列表失败！");
		return false;
	}	
	
	//增加/修改藏品分类
	$("#btn_add_cplb").click(function(){
		add_update_tbl("cplb","藏品分类",'tree');
	});
	//增加/修改自然级别
	$("#btn_add_zrjb").click(function(){
		add_update_tbl("zrjb","自然级别",'tree');
	});
	//增加/修改自然保护方式
	$("#btn_add_zrbhfs").click(function(){
		add_update_tbl("zrbhfs","自然保护方式",'tree');
	});
	//增加/修改年代
	$("#btn_add_nd").click(function(){
		add_update_tbl("nd","年代",'tree');
	});
	//增加/修改质地
	$("#btn_add_zd").click(function(){
		add_update_tbl("zd","质地",'tree');
	});
	
	//增加/修改保管部门
	$("#btn_add_bgbm").click(function(){
		add_update_tbl("bgbm","保管部门",'Table');
	});
	//增加/修改文物普查类别
	$("#btn_add_wwlb").click(function(){
		add_update_tbl("wwlb","文物普查类别",'Table');
	});
	//增加/修改藏品级别
	$("#btn_add_cpjb").click(function(){
		add_update_tbl("cpjb","藏品级别",'Table');
	});
	//增加/修改质量范围
	$("#btn_add_zlfw").click(function(){
		add_update_tbl("zlfw","质量范围",'Table');
	});
	//增加/修改传统数量单位
	$("#btn_add_ctsldw").click(function(){
		add_update_tbl("ctsldw","传统数量单位",'Table');
	});
	//增加/修改实际数量单位
	$("#btn_add_sjsldw").click(function(){
		add_update_tbl("sjsldw","实际数量单位",'Table');
	});
	//增加/修改来源方式
	$("#btn_add_lyfs").click(function(){
		add_update_tbl("lyfs","来源方式",'Table');
	});
	//增加/修改完残程度
	$("#btn_add_wccd").click(function(){
		add_update_tbl("wccd","完残程度",'Table');
	});
	//增加/修改保存状态
	$("#btn_add_bczt").click(function(){
		add_update_tbl("bczt","保存状态",'Table');
	});
	//增加/修改雌雄
	$("#btn_add_cx").click(function(){
		add_update_tbl("cx","雌雄",'Table');
	});
	//增加/修改甲骨材质
	$("#btn_add_jgcz").click(function(){
		add_update_tbl("jgcz","甲骨材质",'Table');
	});
	//增加/修改甲骨组类
	$("#btn_add_jgzl").click(function(){
		add_update_tbl("jgzl","甲骨组类",'Table');
	});
	//增加/修改甲骨五期
	$("#btn_add_jgwq").click(function(){
		add_update_tbl("jgwq","甲骨五期",'Table');
	});
	//增加/修改甲骨辞类
	$("#btn_add_jgcl").click(function(){
		add_update_tbl("jgcl","甲骨辞类",'Table');
	});
	//增加/修改甲骨内容
	$("#btn_add_jgnr").click(function(){
		add_update_tbl("jgnr","甲骨内容",'Table');
	});
	//增加/修改甲骨旧藏
	$("#btn_add_jgjc").click(function(){
		add_update_tbl("jgjc","甲骨旧藏",'Table');
	});
	//增加/修改岩矿分类
	$("#btn_add_ykfl").click(function(){
		add_update_tbl("ykfl","岩矿分类",'Table');
	});
	//增加/修改保护优先等级
	$("#btn_add_bhyxdj").click(function(){
		add_update_tbl("bhyxdj","保护优先等级",'Table');
	});
	//增加/修改拍摄方向
	$("#btn_add_psfx").click(function(){
		add_update_tbl("psfx","拍摄方向",'Table');
	});
	
	//增加部门分管馆长
	$("#btn_add_bmgz").click(function(){		
        if(checkform('#form_bmgz')){
    		var params =$('#form_bmgz').serializeObject();
    	    params["bmmc"] = $("#form_bmgz select[name=bmid]").find("option:selected").text();;
    		params["fggzmc"] = $("#form_bmgz select[name=fggzid]").find("option:selected").text();;
		result = ajaxResult("post",false,ProjectName+"/sysmanage.addFggz.do",params);
		   if(result["status"] == 'ok'){
			   alertFunc("增加部门分管馆长成功！");		
			   $('#bmgzModal').modal('hide');
			   $('#jb_bmgz').bootstrapTable('refresh');
		   }else{
			   alertFunc(result["message"]);
		   }
        }
	});
})

//增加/修改内容提交
function add_update_tbl(tabname,alertInfo,treeOrTable){		
	if(checkform('#form_'+tabname)){
		var params =$('#form_'+tabname).serializeObject();
	    params["tableName"] = "jb_"+tabname;
	    var recordID="";	
	    recordID = params["id"];
	    var result="";	    
	    var selID ="";
	    switch(tabname){
	    	case "cplb":
	    		selID = cplbSelectedId;
	    		break;
	    	case "zrjb":
	    		selID = zrjbSelectedId;
	    		break;
	    	case "zrbhfs":
	    		selID = zrbhfsSelectedId;
	    		break;
	    	case "nd":
	    		selID = ndSelectedId;
	    		break;
	    	case "zd":
	    		selID = zdSelectedId;
	    		break;
	    }
		if(recordID == undefined ||recordID == null || recordID== ""){  //添加	 
			if(treeOrTable == 'tree'){//添加树
			   result = ajaxResult("post",false,ProjectName+"/sysmanage.addTreeNode.do",params);
			   if(result["status"] == 'ok'){
				   alertFunc("增加"+alertInfo+"信息成功！");		
				   $('#'+tabname+'Modal').modal('hide');
				   var params = {'tableName':'jb_'+tabname,'id':selID};
				   $("#jb_"+tabname).bootstrapTable('refresh',{query:params});
				   //刷新ztree											    
				   refreshTreeNode(tabname);			   
			   }else{
				   alertFunc(result["message"]);
			   }	
			}else{//添加表格
			   result = ajaxResult("post",false,ProjectName+"/sysmanage.addRowInTable.do",params);
			   if(result["status"] == 'ok'){
				   alertFunc("增加"+alertInfo+"信息成功！");		
				   $('#'+tabname+'Modal').modal('hide');
				   $('#jb_'+tabname).bootstrapTable('refresh');
			   }else{
				   alertFunc(result["message"]);
			   }	
			}
		}else{//修改	  
			if(treeOrTable == 'tree'){//修改树
				result = ajaxResult("post",false,ProjectName+"/sysmanage.updateTreeNode.do",params);
				if(result["status"] == 'ok'){
				   alertFunc("修改"+alertInfo+"信息成功！");		
				   $('#'+tabname+'Modal').modal('hide');
				   //刷新点击树节点 显示的表格
				   var params = {'tableName':'jb_'+tabname,'id':selID};
				   $("#jb_"+tabname).bootstrapTable('refresh',{query:params});
				   //刷新ztree											    
				   refreshTreeNode(tabname);	
				}else{
					alertFunc(result["message"]);
				}
			}else{//修改表格
				result = ajaxResult("post",false,ProjectName+"/sysmanage.UpdateTable.do",params);
				if(result["status"] == 'ok'){
					alertFunc("修改"+alertInfo+"信息成功！");		
					$('#'+tabname+'Modal').modal('hide');
					$('#jb_'+tabname).bootstrapTable('refresh');
				}else{
					alertFunc(result["message"]);
				}
				//需要表单中的hidden
				$("input[type='hidden']").val("");
			}
		}
	}
}

 

//删除树节点
function deleteTreeNode(tableName){
	bootbox.confirm("删除记录后不能恢复，确认删除当前记录吗？",function(r){
	if(r){			
		   var treeNodeid ="";
		   var result="";
		   if(tableName == 'cplb'){
			   var treeNodeid = cplbSelectedId;
			    result = ajaxResult("post",false,ProjectName+"/sysmanage.deleteTreeNode.do",{'tableName':'jb_cplb','treeNodeid':treeNodeid});
			    cplbSelectedId="";
			    cplbSelectedName="";
		   }else if(tableName == 'zrjb'){
			   var treeNodeid = zrjbSelectedId;
			   result = ajaxResult("post",false,ProjectName+"/sysmanage.deleteTreeNode.do",{'tableName':'jb_zrjb','treeNodeid':treeNodeid});
			   zrjbSelectedId="";
		       zrjbSelectedName="";
		   }else if(tableName == 'zrbhfs'){
			   var treeNodeid = zrbhfsSelectedId;
			   result = ajaxResult("post",false,ProjectName+"/sysmanage.deleteTreeNode.do",{'tableName':'jb_zrbhfs','treeNodeid':treeNodeid});
			   zrbhfsSelectedId="";
		       zrbhfsSelectedName="";
		   }else if(tableName == 'nd'){
			   var treeNodeid = ndSelectedId;
			   result = ajaxResult("post",false,ProjectName+"/sysmanage.deleteTreeNode.do",{'tableName':'jb_nd','treeNodeid':treeNodeid});
			   ndSelectedId="";
		       ndSelectedName="";
		   }else if(tableName == 'zd'){
			   var treeNodeid = zdSelectedId;
			   result = ajaxResult("post",false,ProjectName+"/sysmanage.deleteTreeNode.do",{'tableName':'jb_zd','treeNodeid':treeNodeid});
			   zdSelectedId="";
		       zdSelectedName="";
		   }
		   $('#'+tableName+'parentNode').val("");
		   $('#'+tableName+'parentNodeName').val("");
		if(result["status"] == 'ok'){
			refreshTreeNode(tableName);
		}
	  }
	});
}

//刷新树
function refreshTreeNode(tableName){	 
	if(tableName == 'cplb'){		
		   treeNodesCplb = ajaxResult("post",false,ProjectName+"/sysmanage.getTreeNodes.do",{'tableName':'jb_cplb'});
		   zTreeObjCplb = $.fn.zTree.init($("#ztreeCplb"), settingCplb, treeNodesCplb.rows);
		   if(cplbSelectedId==""){
			 //设置默认选择第一个节点
			   cplbSelectedId = treeNodesCplb.rows[0].id;
				cplbSelectedName = treeNodesCplb.rows[0].name;
		   }		
		   var cplbNodeObject = zTreeObjCplb.getNodeByParam("id",cplbSelectedId,null);
		   zTreeObjCplb.selectNode(cplbNodeObject);
	   }else if(tableName == 'zrjb'){
		   treeNodesZrjb = ajaxResult("post",false,ProjectName+"/sysmanage.getTreeNodes.do",{'tableName':'jb_zrjb'});
		   zTreeObjZrjb = $.fn.zTree.init($("#ztreeZrjb"), settingZrjb, treeNodesZrjb.rows);
		   if(zrjbSelectedId==""){
			 //设置默认选择第一个节点
			   zrjbSelectedId = treeNodesZrjb.rows[0].id;
				zrjbSelectedName = treeNodesZrjb.rows[0].name;
		   }	
		   var zrjbNodeObject = zTreeObjZrjb.getNodeByParam("id",zrjbSelectedId,null);
		   zTreeObjZrjb.selectNode(zrjbNodeObject);
	   }else if(tableName == 'zrbhfs'){
		   treeNodesZrbhfs = ajaxResult("post",false,ProjectName+"/sysmanage.getTreeNodes.do",{'tableName':'jb_zrbhfs'});
		   zTreeObjZrbhfs = $.fn.zTree.init($("#ztreeZrbhfs"), settingZrbhfs, treeNodesZrbhfs.rows);
		   if(zrbhfsSelectedId==""){
			 //设置默认选择第一个节点
			   zrbhfsSelectedId = treeNodesZrbhfs.rows[0].id;
				zrbhfsSelectedName = treeNodesZrbhfs.rows[0].name;
		   }	
		   var zrbhfsNodeObject = zTreeObjZrbhfs.getNodeByParam("id",zrbhfsSelectedId,null);
		   zTreeObjZrbhfs.selectNode(zrbhfsNodeObject);
	   }else if(tableName == 'nd'){
		   treeNodesNd = ajaxResult("post",false,ProjectName+"/sysmanage.getTreeNodes.do",{'tableName':'jb_nd'});
		   zTreeObjNd = $.fn.zTree.init($("#ztreeNd"), settingNd, treeNodesNd.rows);
		   if(ndSelectedId==""){
			 //设置默认选择第一个节点
			   ndSelectedId = treeNodesNd.rows[0].id;
				ndSelectedName = treeNodesNd.rows[0].name;
		   }	
		   var ndNodeObject = zTreeObjNd.getNodeByParam("id",ndSelectedId,null);
		   zTreeObjNd.selectNode(ndNodeObject);
	   }else if(tableName == 'zd'){
		   treeNodesZd = ajaxResult("post",false,ProjectName+"/sysmanage.getTreeNodes.do",{'tableName':'jb_zd'});
		   zTreeObjZd = $.fn.zTree.init($("#ztreeZd"), settingZd, treeNodesZd.rows);
		   if(zdSelectedId==""){
			 //设置默认选择第一个节点
			   zdSelectedId = treeNodesZd.rows[0].id;
				zdSelectedName = treeNodesZd.rows[0].name;
		   }		   
		   var zdNodeObject = zTreeObjZd.getNodeByParam("id",eval(tableName+'SelectedId'),null);
		   zTreeObjZd.selectNode(zdNodeObject);
	   }	
	   $('#'+tableName+'parentNode').val(eval(tableName+'SelectedId'));				
	   $('#'+tableName+'parentNodeName').val(eval(tableName+'SelectedName'));
}
//打开树节点的增加窗口
function openTreeModalAdd(tblId){
	//$('#form_'+tblId)[0].reset(); 
	$('#form_'+tblId+" input[name=name]").val("");
	var parentid =$("#form_"+tblId+" input[name=parentid]").val();
	if(parentid==0){
		alertFunc("请选择父节点！");
		return false;
	}	
	$("#btn_add_"+tblId).text("增加");
	$('#'+tblId+'Modal').modal('show');
}
//打开树节点的增加窗口（根节点）
function openTopTreeModalAdd(tblId){
	//$('#form_'+tblId)[0].reset(); 
	$('#form_'+tblId+" input[name=name]").val("");
	$('#form_'+tblId+" input[name=id]").val("");
	$("#form_"+tblId+" input[name=parentid]").val("0");
	$("#form_"+tblId+" #"+tblId+"parentNodeName").val("无");
	$("#btn_add_"+tblId).text("增加");
	$('#'+tblId+'Modal').modal('show');
}

//打开树节点的修改窗口（根节点）
function updateTreeNode(tblId){
	$("#form_"+tblId+" input[name=parentid]").val("0");
	$("#form_"+tblId+" #"+tblId+"parentNodeName").val("无");
	switch(tblId){
	case "cplb":
		$("#form_"+tblId+" input[name=id]").val(cplbSelectedId);
		$("#form_"+tblId+" input[name=name]").val(cplbSelectedName);
		break;
	case "zrjb":
		$("#form_"+tblId+" input[name=id]").val(zrjbSelectedId);
		$("#form_"+tblId+" input[name=name]").val(zrjbSelectedName);
		break;
	case "zrbhfs":
		$("#form_"+tblId+" input[name=id]").val(zrbhfsSelectedId);
		$("#form_"+tblId+" input[name=name]").val(zrbhfsSelectedName);
		break;
	case "nd":
		$("#form_"+tblId+" input[name=id]").val(ndSelectedId);
		$("#form_"+tblId+" input[name=name]").val(ndSelectedName);
		break;
	case "zd":
		$("#form_"+tblId+" input[name=id]").val(zdSelectedId);
		$("#form_"+tblId+" input[name=name]").val(zdSelectedName);
		break;
	}
	$("#btn_add_"+tblId).text("修改");
	$('#'+tblId+'Modal').modal('show');
}

//点击增加按钮，改变模态框中保存按钮的值
function modal_add(tabname){
	$('#form_'+tabname)[0].reset(); //清空form
	$("#btn_add_"+tabname).text("增加");
}

//点击修改按钮，填充修改表单
function modal_modi(data){
	var tabname = currentJb.replace("jb_","");
	loadData("#form_"+tabname,data);	
	$("#btn_add_"+tabname).text("修改");
	$('#'+tabname+'Modal').modal('show');
}

//删除记录
function del_jb(id){		
	var params = new Object();
	params["id"] = id;
	params["tableName"] = currentJb;	
	delRecord("#"+currentJb,"/sysmanage.deleteRowInTable.do",params);	
}

//删除部门分管馆长记录
function del_bmgz(data){
	var params = new Object();
	params["bmid"] = data.bmid;
	params["fggzid"] = data.fggzid;		
	delRecord("#jb_bmgz","/sysmanage.deleteFggz.do",params);	
}

//树用的删除记录
function tree_del_jb(id){		
	var params = new Object();
	params["id"] = id;
	params["tableName"] = currentJb;	
	treeDelRecord("#"+currentJb,"/sysmanage.deleteRowInTable.do",params);	
}

//树用的删除表中记录
function treeDelRecord(tableid,url,params){	
	bootbox.setLocale("zh_CN");
	bootbox.confirm("删除记录后不能恢复，确认删除当前记录吗？",function(r){
		if(r){
			result = ajaxResult("post",false,ProjectName+url,params);
		   if(result["status"] == 'ok'){
			   alertFunc("记录删除成功！");			
			   //$(tableid).bootstrapTable('refresh');
			   $(tableid).bootstrapTable('removeAll');
			   //根据点击行id，获取父节点id，然后获取父节点的全部下一级节点
			   var result = ajaxResult('GET',false,ProjectName+"/sysmanage.getTableByTreeSubId.do",params)
			   $(tableid).bootstrapTable('load',result);
			   
			  // var params = {'tableName':'jb_'+tabname,'id':selID};
			  // $("#jb_"+tabname).bootstrapTable('refresh',{query:params});
			   
			   //刷新树
			   refreshTreeNode(tableName);			   
		   }else{
			   alertFunc(result["error"]);
		   }
		}
	});
}

/* 保管部门表头开始  */
var bgbmColumns=[{
	 field: 'id',
	 visible:false
    },{
	 field: 'name',
	 title: '保管部门名称'
    },{
     field: 'sorted',
	 title: '排序编号'
    },{
     field: 'operate',
     title: '操作',
     formatter : operateFormat
    }];

/* 库房基表表头开始  */
var kfjbColumns=[{
	 field: 'check',
	 checkbox: true
   },{
	 field: 'id',
	 visible:false
   },{
	 field: 'bgbmid',
	 title: '保管部门id'
   },{
    field: 'bgbmmc',
	 title: '保管部门名称'
   },{
    field: 'cpflid',
    title: '藏品分类id'
   },{
    field: 'cpflmc',
  	 title: '藏品分类名称'
   },{
    field: 'operate',
    title: '操作',
    formatter : operateFormat
   }];

/* 文物普查类别表头开始  */
var wwlbColumns=[{
	 field: 'id',
	 visible:false
    },{
	 field: 'name',
	 title: '文物普查类别名称'
    },{
     field: 'sorted',
	 title: '排序编号'
    },{
     field: 'operate',
     title: '操作',
     formatter : operateFormat
    }];

/* 藏品级别表头开始  */
var cpjbColumns=[{
	 field: 'id',
	 visible:false
    },{
	 field: 'name',
	 title: '藏品级别名称'
    },{
     field: 'sorted',
	 title: '排序编号'
    },{
     field: 'operate',
     title: '操作',
     formatter : operateFormat
    }];

/* 质量范围表头开始  */
var zlfwColumns=[{
	 field: 'id',
	 visible:false
    },{
	 field: 'name',
	 title: '质量范围名称'
    },{
     field: 'sorted',
	 title: '排序编号'
    },{
     field: 'operate',
     title: '操作',
     formatter : operateFormat
    }];
/* 传统数量单位表头开始  */
var ctsldwColumns=[{
	 field: 'id',
	 visible:false
    },{
	 field: 'name',
	 title: '单位名称'
    },{
     field: 'sorted',
	 title: '排序编号'
    },{
     field: 'operate',
     title: '操作',
     formatter : operateFormat
    }];
/* 实际数量单位表头开始  */
var sjsldwColumns=[{
	 field: 'id',
	 visible:false
   },{
	 field: 'name',
	 title: '单位名称'
   },{
    field: 'sorted',
	 title: '排序编号'
   },{
    field: 'operate',
    title: '操作',
    formatter : operateFormat
   }];
/* 来源方式表头开始  */
var lyfsColumns=[{
	 field: 'id',
	 visible:false
    },{
	 field: 'name',
	 title: '来源方式名称'
    },{
     field: 'sorted',
	 title: '排序编号'
    },{
     field: 'operate',
     title: '操作',
     formatter : operateFormat
    }];

/*完残程度表头开始 */
var wccdColumns=[{
	 field: 'id',
	 visible:false
    },{
	 field: 'name',
	 title: '完残程度名称'
   },{
    field: 'sorted',
	 title: '排序编号'
   },{
    field: 'operate',
    title: '操作',
    formatter : operateFormat
   }];

/* 保存状态表头开始  */
var bcztColumns=[{
	 field: 'id',
	 visible:false
    },{
	 field: 'name',
	 title: '保存状态名称'
   },{
    field: 'sorted',
	 title: '排序编号'
   },{
    field: 'operate',
    title: '操作',
    formatter : operateFormat
   }];

/* 雌雄表头开始  */
var cxColumns=[{
	 field: 'id',
	 visible:false
    },{
	 field: 'name',
	 title: '雌雄名称'
   },{
    field: 'sorted',
	 title: '排序编号'
   },{
    field: 'operate',
    title: '操作',
    formatter : operateFormat
   }];

/* 甲骨材质表头开始  */
var jgczColumns=[{
	 field: 'id',
	 visible:false
    },{
	 field: 'name',
	 title: '甲骨材质名称'
   },{
    field: 'sorted',
	 title: '排序编号'
   },{
    field: 'operate',
    title: '操作',
    formatter : operateFormat
   }];

/* 甲骨组类表头开始  */
var jgzlColumns=[{
	 field: 'id',
	 visible:false
    },{
	 field: 'name',
	 title: '甲骨组类名称'
   },{
    field: 'sorted',
	 title: '排序编号'
   },{
    field: 'operate',
    title: '操作',
    formatter : operateFormat
   }];

/* 甲骨五期表头开始  */
var jgwqColumns=[{
	 field: 'id',
	 visible:false
    },{
	 field: 'name',
	 title: '甲骨五期名称'
   },{
    field: 'sorted',
	 title: '排序编号'
   },{
    field: 'operate',
    title: '操作',
    formatter : operateFormat
   }];


/* 甲骨辞类表头开始  */
var jgclColumns=[{
	 field: 'id',
	 visible:false
    },{
	 field: 'name',
	 title: '甲骨辞类名称'
   },{
    field: 'sorted',
	 title: '排序编号'
   },{
    field: 'operate',
    title: '操作',
    formatter : operateFormat
   }];

/* 甲骨内容表头开始  */
var jgnrColumns=[{
	 field: 'id',
	 visible:false
    },{
	 field: 'name',
	 title: '甲骨内容名称'
   },{
    field: 'sorted',
	 title: '排序编号'
   },{
    field: 'operate',
    title: '操作',
    formatter : operateFormat
   }];

/* 甲骨旧藏表头开始  */
var jgjcColumns=[{
	 field: 'id',
	 visible:false
    },{
	 field: 'name',
	 title: '甲骨旧藏名称'
   },{
    field: 'sorted',
	 title: '排序编号'
   },{
    field: 'operate',
    title: '操作',
    formatter : operateFormat
   }];

/* 岩矿分类表头开始  */
var ykflColumns=[{
	 field: 'id',
	 visible:false
    },{
	 field: 'name',
	 title: '岩矿分类名称'
   },{
    field: 'sorted',
	 title: '排序编号'
   },{
    field: 'operate',
    title: '操作',
    formatter : operateFormat
   }];

/* 保护优先等级表头开始  */
var bhyxdjColumns=[{
	 field: 'id',
	 visible:false
    },{
	 field: 'name',
	 title: '保护优先等级名称'
   },{
    field: 'sorted',
	 title: '排序编号'
   },{
    field: 'operate',
    title: '操作',
    formatter : operateFormat
   }];

/* 拍摄方向表头开始  */
var psfxColumns=[{
	 field: 'id',
	 visible:false
    },{
	 field: 'name',
	 title: '拍摄方向名称'
   },{
    field: 'sorted',
	 title: '排序编号'
   },{
    field: 'operate',
    title: '操作',
    formatter : operateFormat
   }];

/* 部门分管馆长表头开始  */
var bmgzColumns=[{
	 field: 'id',
	 visible:false
    },{
	 field: 'bmmc',
	 title: '部门名称'
   },{
	 field: 'fggzmc',
	 title: '分管馆长'
   },{
    field: 'operate',
    title: '操作',
    formatter : function(value, row, index) {
    		return "<a onclick='del_bmgz("+JSON.stringify(row)+")' href='javascript:void(0)'>删除</a>";
  		}
   }];

/* 树形结构表头开始  */
var treeColumns=[{
	 field: 'name',
	 title: '名称'
   },{
    field: 'operate',
    title: '操作',
    formatter : treeOperateFormat
   }];

//表格操作列
function operateFormat(value, row, index) {  	
  	return "<a onclick='modal_modi("+JSON.stringify(row)+")' href='javascript:void(0)'>修改</a>&nbsp;&nbsp;&nbsp;<a onclick='del_jb("+row.id+")' href='javascript:void(0)'>删除</a>";
} 


//树用的表格操作列
function treeOperateFormat(value, row, index) {  	
  	return "<a onclick='modal_modi("+JSON.stringify(row)+")' href='javascript:void(0)'>修改</a>";
} 








